﻿$(document).ready(function () {
    var app = $("#table-list").uTable({
        url: "IExample",
        multiple: true,
        checkbox: {
            enable: true
        },
        buttons: [
            {
                text: "新增", style: "btn-primary", click: function () {
                    EditDetail();
                }
            },
            {
                text: "弹出层新增", style: "btn-primary", click: function () {
                    EditMDetail();
                }
            }
        ],
        heads: [{ num:true, name: "序号" },
            { key: "Name", name: "名称" },
            { key: "ChineseName", name: "中文名" },
            { html: '<a href="javascript:" class="edit" data-id="{{ID}}" >修改</a> <a href="javascript:" class="medit" data-id="{{ID}}" >弹窗修改</a> <a href="javascript:" class="del" data-id="{{ID}}" >删除</a>', name: "操作" }
        ]
    });

    //编辑
    $("#table-list").on("click", ".edit", function () {
        var id = $(this).attr("data-id");
        EditDetail(id);
    });

    //删除
    $("#table-list").on("click", ".del", function () {
        var id = $(this).attr("data-id");
        $.msg.confirm("确定要删除吗？", function () {
            //$.get(); 删除业务
        });
    });

    //弹窗编辑
    $("#table-list").on("click", ".medit", function () {
        var id = $(this).attr("data-id");
        EditMDetail(id);
    });

    //展示编辑内容
    function EditDetail(id) {
        ///展示详细编辑页面
        $.layout.detail("VExample/Edit", function () {
            $("#edit-form").Form({
                url: id ? "IExample/Get?id=" + id : "",
                success: function () {
                    $.layout.back();//回到列表
                    app.refresh();//刷新列表
                }
            });
        });
    }

    //弹窗展示编辑内容
    function EditMDetail(id) {
        ///展示详细编辑页面
        $("#modaltemplatebox").modal({
            title: "见证记录",
            width:"800",
            url: "VExample/Edit",
            buttons: [
                { text: "关闭", click: function () { /*逻辑处理*/$(this).close(); } }
            ],
            afterCreate: function () {
                $("#edit-form").Form({
                    url: id ? "IExample/Get?id=" + id : "",
                    success: function () {
                        $("#modaltemplatebox").close();//关闭窗口
                        app.refresh();//刷新列表
                    }
                });
            }
        });
    }
});